package itemCF.step1;


import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @author legolas
 * @date 2020/3/13 下午7:06

 */

public class Mapper1 extends Mapper<LongWritable, Text, Text, Text> {

    /**
     * 需要实现的map函数
     * 这个map函数就是可以接收k1，v1   产生k2，v2
     *
     * @param k1
     * @param v1
     * @param context
     * @throws IOException
     * @throws InterruptedException
     */

    @Override
    protected void map(LongWritable k1, Text v1, Context context) throws IOException, InterruptedException {
        String[] values = v1.toString().split(",");
        String userID = values[0];
        String itemID = values[1];
        String score = values[2];

        Text k2 = new Text();
        Text v2 = new Text();
        k2.set(itemID);
        v2.set(userID + "_" + score);
        context.write(k2, v2);

    }
}
